package com.glp.services.impl;

import com.glp.common.constants.FileConstants;
import com.glp.common.constants.GlpConstants;
import com.glp.dao.custom.ReportAuditMapper;
import com.glp.dao.custom.ReportMapper;
import com.glp.pojo.Report;
import com.glp.pojo.ReportAudit;
import com.glp.pojo.User;
import com.glp.pojo.dto.AuditDTO;
import com.glp.pojo.dto.ReportDTO;
import com.glp.services.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URLEncoder;
import java.util.*;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;
    @Autowired
    private ReportAuditMapper reportAuditMapper;

    @Override
    public Report getReportById(Integer reportId) {
        return reportMapper.selectByPrimaryKey(reportId);
    }

    @Override
    @Transactional
    public int addReport(Report report, Integer status) {
        int i = 1;
        try {
            //warn 注意这里  返回主键id
            int c1 = reportMapper.insertSelective(report);
            //插入之后进行添加审核进度
            ReportAudit audit = new ReportAudit();
            audit.setReportId(report.getReportId());
            audit.setStatus(status);
            int c2 = reportAuditMapper.insertSelective(audit);
            if (c1 + c2 < 2) {
                throw new Exception("操作失败！插入数据不完整！");
            }
        } catch (Exception e) {
            i = 0;
            e.printStackTrace();
        }
        return i;
    }

    @Override
    public int modifyReport(Report report) {
        return reportMapper.updateByPrimaryKeySelective(report);
    }

    @Override
    public List<ReportDTO> getReportByStatus(Integer status) {
        List<ReportDTO> list;
        if(ObjectUtils.isEmpty(status)){
            return reportMapper.selectByStatus(status);
        }
        if(status == GlpConstants.REPORT_STATUS4){
            list = reportMapper.selectRatifyPass();
        }else{
            list = reportMapper.selectByStatus(status);
        }
        return list;
    }

    @Override
    public List<ReportDTO> getReportByStatusAndUId(Integer status, Integer uid) {
        return reportMapper.selectByStatusAndUId(status, uid);
    }

    @Override
    public boolean judgeReportIsRemove(Integer reportId, Integer status) {
        User curUser = (User) SecurityUtils.getSubject().getPrincipal();
        //判断是不是自己的报告
        Report report = reportMapper.selectByPrimaryKey(reportId);
        if (!report.getCreateBy().equals(curUser.getUserId())) {
            return false;
        }
        //判断报告状态 , 只有在报告为保存 ， 未审核通过时才能被删除
        if (!(status.equals(GlpConstants.REPORT_STATUS3)
                || status.equals(GlpConstants.REPORT_STATUS5)
                || status.equals(GlpConstants.REPORT_STATUS0))) {
            return false;
        }
        return true;
    }

    @Override
    public int remove(Integer reportId) {
        return reportMapper.deleteByPrimaryKey(reportId);
    }

    @Override
    public void delReportImage(Integer reportId) {
        Report report = getReportById(reportId);
        List<String> list = new LinkedList<>();
        list.add(report.getJxztzp());
        list.add(report.getClmpzp());
        list.add(report.getFdjmpzp());
        list.add(report.getHclzzzp());
        list.add(report.getJczp());
        list.add(report.getJgzp());
        for (String s : list) {
            if (StringUtils.isEmpty(s)) {
                continue;
            }
            String fileName = s.substring(s.lastIndexOf("/"));
            File file = new File(FileConstants.REPORT_IMG_LOCAL_URL + fileName);
            if (file.exists()) {
                file.delete();
            }
        }
    }


    @Override
    public int auditReport(AuditDTO auditDTO) {
        ReportAudit reportAudit = reportAuditMapper.selectByReportId(auditDTO.getReportId());
        User curUser = (User) SecurityUtils.getSubject().getPrincipal();
        //因为 报告的status 和 审核表中的状态 是要保持一致的 ， 所以这里同时修改报告状态
        Report report = new Report();
        report.setReportId(auditDTO.getReportId());
        report.setStatus(auditDTO.getStatus());
        ReportAudit audit = new ReportAudit();
        audit.setAuditId(reportAudit.getAuditId());
        audit.setUpdateTime(new Date());
        audit.setStatus(auditDTO.getStatus());
        audit.setReportId(auditDTO.getReportId());
        int count1, count2;
        if (auditDTO.getStatus() == GlpConstants.REPORT_STATUS2) {
            audit.setAuditBy(curUser.getUserId());
        } else if (auditDTO.getStatus() == GlpConstants.REPORT_STATUS4) {
            audit.setRatifyBy(curUser.getUserId());
        } else if (auditDTO.getStatus() == GlpConstants.REPORT_STATUS3) {
            audit.setAuditMsg(auditDTO.getMsg());
            audit.setAuditBy(curUser.getUserId());
        } else if (auditDTO.getStatus() == GlpConstants.REPORT_STATUS5) {
            audit.setRatifyMsg(auditDTO.getMsg());
            audit.setRatifyBy(curUser.getUserId());
        }
        count1 = reportAuditMapper.updateByPrimaryKeySelective(audit);
        count2 = reportMapper.updateByPrimaryKeySelective(report);
        return count1 + count2;
    }

    @Override
    public int modifyReportStatus(Integer reportId, int status) {
        int count1, count2;
        ReportAudit audit = reportAuditMapper.selectByReportId(reportId);
        audit.setUpdateTime(new Date());
        audit.setStatus(status);
        Report report = new Report();
        report.setReportId(reportId);
        report.setStatus(status);
        count1 = reportAuditMapper.updateByPrimaryKeySelective(audit);
        count2 = reportMapper.updateByPrimaryKeySelective(report);
        return count1 + count2;
    }

    /**
     * 中诺模板
     * @param info
     * @param response
     */
    @Override
    public void exportZNReportExcel(Report info, HttpServletResponse response) {
        XSSFWorkbook wb = null;
        try {
            wb = new XSSFWorkbook(new FileInputStream(FileConstants.REPORT_ZN_MODAL_URL));
        } catch (IOException e) {
            e.printStackTrace();
        }
        XSSFSheet sheet = wb.getSheetAt(0);
        XSSFCell c3_3 = sheet.getRow(3).getCell(3);
        XSSFCell c3_11 = sheet.getRow(3).getCell(11);
        c3_3.setCellValue(info.getJcbgbh());
        c3_11.setCellValue(info.getJxjcrq());
        XSSFCell c4_3 = sheet.getRow(4).getCell(3);
        XSSFCell c4_11 = sheet.getRow(4).getCell(11);
        c4_3.setCellValue(info.getYjbz());
        c4_11.setCellValue(info.getJyff());
        XSSFCell c5_3 = sheet.getRow(5).getCell(3);
        XSSFCell c5_11 = sheet.getRow(5).getCell(11);
//        c5_3.setCellValue(info.getJyjg());
//        c5_11.setCellValue(info.getJgdz());
        XSSFCell c7_3 = sheet.getRow(7).getCell(3);
        XSSFCell c7_11 = sheet.getRow(7).getCell(11);
        c7_3.setCellValue(info.getXmdw());
        c7_11.setCellValue(info.getLxdh());
        XSSFCell c8_3 = sheet.getRow(8).getCell(3);
        c8_3.setCellValue(info.getSyrdz());
        XSSFCell c10_3 = sheet.getRow(10).getCell(3);
        c10_3.setCellValue(info.getSbscdw());
        XSSFCell c11_3 = sheet.getRow(11).getCell(3);
        c11_3.setCellValue(info.getFdjzzcmc());
        XSSFCell c12_3 = sheet.getRow(12).getCell(3);
        XSSFCell c12_11 = sheet.getRow(12).getCell(11);
//        c12_3.setCellValue(info.getXlh());   //序列号
//        c12_11.setCellValue(info.getHbbh());   //环保编号
        XSSFCell c13_3 = sheet.getRow(13).getCell(3);
        XSSFCell c13_11 = sheet.getRow(13).getCell(11);
        c13_3.setCellValue(info.getJxhbhp());
        c13_11.setCellValue(info.getSbph());
        XSSFCell c14_3 = sheet.getRow(14).getCell(3);
        XSSFCell c14_11 = sheet.getRow(14).getCell(11);
        c14_3.setCellValue(info.getJxmc());
        c14_11.setCellValue(info.getSb());
        XSSFCell c15_3 = sheet.getRow(15).getCell(3);
        XSSFCell c15_11 = sheet.getRow(15).getCell(11);
        c15_3.setCellValue(info.getJxxh());
        c15_11.setCellValue(info.getCcrq());
        XSSFCell c16_3 = sheet.getRow(16).getCell(3);
        XSSFCell c16_11 = sheet.getRow(16).getCell(11);
        c16_3.setCellValue(info.getSbys());
        c16_11.setCellValue(info.getPfbjzbq());
        XSSFCell c17_3 = sheet.getRow(17).getCell(3);
        XSSFCell c17_11 = sheet.getRow(17).getCell(11);
        c17_3.setCellValue(info.getJcyj());
        c17_11.setCellValue(info.getJyff());
        XSSFCell c18_3 = sheet.getRow(18).getCell(3);
        XSSFCell c18_11 = sheet.getRow(18).getCell(11);
        c18_3.setCellValue(info.getJxvinm());
        c18_11.setCellValue(info.getFdjbh());
        XSSFCell c19_3 = sheet.getRow(19).getCell(3);
        XSSFCell c19_11 = sheet.getRow(19).getCell(11);
        c19_3.setCellValue(info.getPfjd());
        c19_11.setCellValue(info.getFdjxh());
        XSSFCell c20_3 = sheet.getRow(20).getCell(3);
        XSSFCell c20_11 = sheet.getRow(20).getCell(11);
        c20_3.setCellValue(info.getFdjccnf());
        c20_11.setCellValue(info.getFdjedgl());
        XSSFCell c21_3 = sheet.getRow(21).getCell(3);
        XSSFCell c21_11 = sheet.getRow(21).getCell(11);
        c21_3.setCellValue(info.getYp());
        c21_11.setCellValue(info.getFdjedzs());
        XSSFCell c22_3 = sheet.getRow(22).getCell(3);
        XSSFCell c22_11 = sheet.getRow(22).getCell(11);
//        c22_3.setCellValue(info.getHbxxgkbh());
//        c22_11.setCellValue(info.getFdjxshzh());
        XSSFCell c23_3 = sheet.getRow(23).getCell(3);
        XSSFCell c23_11 = sheet.getRow(23).getCell(11);
        c23_3.setCellValue(info.getJxlx());
        c23_11.setCellValue(info.getJclx());
        XSSFCell c24_3 = sheet.getRow(24).getCell(3);
        XSSFCell c24_11 = sheet.getRow(24).getCell(11);
        c24_3.setCellValue(info.getGztx());
        c24_11.setCellValue(info.getFdjhclxt());
        XSSFCell c25_3 = sheet.getRow(25).getCell(3);
        XSSFCell c25_11 = sheet.getRow(25).getCell(11);
        c25_3.setCellValue(info.getSyjzgpqy());
        c25_11.setCellValue(info.getJsybjxt());
        XSSFCell c26_3 = sheet.getRow(26).getCell(3);
        XSSFCell c26_11 = sheet.getRow(26).getCell(11);
        c26_3.setCellValue(info.getJsxnxzxt());
        c26_11.setCellValue(info.getEcuxx());
        XSSFCell c27_3 = sheet.getRow(27).getCell(3);
        XSSFCell c27_11 = sheet.getRow(27).getCell(11);
        c27_3.setCellValue(info.getYcjkxt());
        c27_11.setCellValue(info.getWxdwxt());
        XSSFCell c29_3 = sheet.getRow(29).getCell(3);
        XSSFCell c29_12 = sheet.getRow(29).getCell(12);
        c29_3.setCellValue(info.getHjwd());
        c29_12.setCellValue(info.getHbgd());
        XSSFCell c30_3 = sheet.getRow(30).getCell(3);
        XSSFCell c30_12 = sheet.getRow(30).getCell(12);
        c30_3.setCellValue(info.getHjsd());
        c30_12.setCellValue(info.getDqyl());
        XSSFCell c33_0 = sheet.getRow(33).getCell(0);
        XSSFCell c33_3 = sheet.getRow(33).getCell(3);
        XSSFCell c33_6 = sheet.getRow(33).getCell(6);
        XSSFCell c33_10 = sheet.getRow(33).getCell(10);
        c33_0.setCellValue(info.getSbmc());
        c33_3.setCellValue(info.getXhgg());
        c33_6.setCellValue(info.getCcbh());
        c33_10.setCellValue(info.getSbjlzs());
        XSSFCell c37_3 = sheet.getRow(37).getCell(3);
        XSSFCell c37_8 = sheet.getRow(37).getCell(8);
        XSSFCell c37_12 = sheet.getRow(37).getCell(12);
        c37_3.setCellValue(info.getJckssj());
        c37_8.setCellValue(info.getJcjssj());
        c37_12.setCellValue(info.getJcdd());
        XSSFCell c39_3 = sheet.getRow(39).getCell(3);
        XSSFCell c39_5 = sheet.getRow(39).getCell(5);
        XSSFCell c39_8 = sheet.getRow(39).getCell(8);
        XSSFCell c39_10 = sheet.getRow(39).getCell(10);
        XSSFCell c39_13 = sheet.getRow(39).getCell(13);
        c39_3.setCellValue(info.getJcjg1());
        c39_5.setCellValue(info.getJcjg2());
        c39_8.setCellValue(info.getJcjg3());
        c39_10.setCellValue(info.getFdjzs());
        c39_13.setCellValue(Integer.valueOf(info.getMsyy()) == 0 ? "不可见" : "可见");
        XSSFCell c41_3 = sheet.getRow(41).getCell(3);
//        c41_3.setCellValue(info.getJg());
        XSSFCell c42_3 = sheet.getRow(42).getCell(3);
        c42_3.setCellValue(info.getPfxz());
        XSSFCell c43_3 = sheet.getRow(43).getCell(3);
        c43_3.setCellValue(info.getJgpd());
        //插入图片
        insertPicCost(wb, sheet, info.getJxztzp(), 0, 46, 8, 57);
        insertPicCost(wb, sheet, info.getClmpzp(), 9, 46, 17, 57);
        insertPicCost(wb, sheet, info.getFdjmpzp(), 0, 58, 8, 70);
        insertPicCost(wb, sheet, info.getHclzzzp(), 9, 58, 17, 70);
        insertPicCost(wb, sheet, info.getJczp(), 0, 71, 8, 80);
        insertPicCost(wb, sheet, info.getJgzp(), 9, 71, 17, 80);
        //浏览器响应下载
        response.setContentType("application/vnd.ms-excel");
        try {
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(info.getJcbgbh() + ".xlsx", "utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        OutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void exportGLPReportExcel(Report info, HttpServletResponse response) {
        XSSFWorkbook wb = null;
        try {
            wb = new XSSFWorkbook(new FileInputStream(FileConstants.REPORT_GLP_MODAL_URL));
        } catch (IOException e) {
            e.printStackTrace();
        }
        XSSFSheet sheet = wb.getSheetAt(0);
        XSSFCell c3_3 = sheet.getRow(3).getCell(3);
        XSSFCell c3_11 = sheet.getRow(3).getCell(11);
        c3_3.setCellValue(info.getJcbgbh());
        c3_11.setCellValue(info.getJxjcrq());
        XSSFCell c7_3 = sheet.getRow(7).getCell(3);
        XSSFCell c7_11 = sheet.getRow(7).getCell(11);
        c7_3.setCellValue(info.getXmdw());
        c7_11.setCellValue(info.getLxdh());
        XSSFCell c8_3 = sheet.getRow(8).getCell(3);
        c8_3.setCellValue(info.getSyrdz());
        XSSFCell c10_3 = sheet.getRow(10).getCell(3);
        c10_3.setCellValue(info.getSbscdw());
        XSSFCell c11_3 = sheet.getRow(11).getCell(3);
        c11_3.setCellValue(info.getFdjzzcmc());
        XSSFCell c12_3 = sheet.getRow(12).getCell(3);
        XSSFCell c12_11 = sheet.getRow(12).getCell(11);
        c12_3.setCellValue(info.getJxhbhp());
        c12_11.setCellValue(info.getSbph());
        XSSFCell c13_3 = sheet.getRow(13).getCell(3);
        XSSFCell c13_11 = sheet.getRow(13).getCell(11);
        c13_3.setCellValue(info.getJxmc());
        c13_11.setCellValue(info.getSb());
        XSSFCell c14_3 = sheet.getRow(14).getCell(3);
        XSSFCell c14_11 = sheet.getRow(14).getCell(11);
        c14_3.setCellValue(info.getJxxh());
        c14_11.setCellValue(info.getCcrq());
        XSSFCell c15_3 = sheet.getRow(15).getCell(3);
        XSSFCell c15_11 = sheet.getRow(15).getCell(11);
        c15_3.setCellValue(info.getSbys());
        c15_11.setCellValue(info.getPfbjzbq());
        XSSFCell c16_3 = sheet.getRow(16).getCell(3);
        XSSFCell c16_11 = sheet.getRow(16).getCell(11);
        c16_3.setCellValue(info.getJcyj());
        c16_11.setCellValue(info.getJyff());
        XSSFCell c17_3 = sheet.getRow(17).getCell(3);
        XSSFCell c17_11 = sheet.getRow(17).getCell(11);
        c17_3.setCellValue(info.getJxvinm());
        c17_11.setCellValue(info.getFdjbh());
        XSSFCell c18_3 = sheet.getRow(18).getCell(3);
        XSSFCell c18_11 = sheet.getRow(18).getCell(11);
        c18_3.setCellValue(info.getPfjd());
        c18_11.setCellValue(info.getFdjxh());
        XSSFCell c19_3 = sheet.getRow(19).getCell(3);
        XSSFCell c19_11 = sheet.getRow(19).getCell(11);
        c19_3.setCellValue(info.getFdjccnf());
        c19_11.setCellValue(info.getFdjedgl());
        XSSFCell c20_3 = sheet.getRow(20).getCell(3);
        XSSFCell c20_11 = sheet.getRow(20).getCell(11);
        c20_3.setCellValue(info.getYp());
        c20_11.setCellValue(info.getFdjedzs());
        XSSFCell c21_3 = sheet.getRow(21).getCell(3);
        XSSFCell c21_11 = sheet.getRow(21).getCell(11);
        c21_3.setCellValue(info.getJxlx());
        c21_11.setCellValue(info.getJclx());
        XSSFCell c22_3 = sheet.getRow(22).getCell(3);
        XSSFCell c22_11 = sheet.getRow(22).getCell(11);
        c22_3.setCellValue(info.getGztx());
        c22_11.setCellValue(info.getFdjhclxt());
        XSSFCell c23_3 = sheet.getRow(23).getCell(3);
        XSSFCell c23_11 = sheet.getRow(23).getCell(11);
        c23_3.setCellValue(info.getSyjzgpqy());
        c23_11.setCellValue(info.getJsybjxt());
        XSSFCell c24_3 = sheet.getRow(24).getCell(3);
        XSSFCell c24_11 = sheet.getRow(24).getCell(11);
        c24_3.setCellValue(info.getJsxnxzxt());
        c24_11.setCellValue(info.getEcuxx());
        XSSFCell c25_3 = sheet.getRow(25).getCell(3);
        XSSFCell c25_11 = sheet.getRow(25).getCell(11);
        c25_3.setCellValue(info.getYcjkxt());
        c25_11.setCellValue(info.getWxdwxt());
        XSSFCell c27_3 = sheet.getRow(27).getCell(3);
        XSSFCell c27_11 = sheet.getRow(27).getCell(11);
        c27_3.setCellValue(info.getHjwd());
        c27_11.setCellValue(info.getHbgd());
        XSSFCell c28_3 = sheet.getRow(28).getCell(3);
        XSSFCell c28_11 = sheet.getRow(28).getCell(11);
        c28_3.setCellValue(info.getHjsd());
        c28_11.setCellValue(info.getDqyl());
        XSSFCell c31_3 = sheet.getRow(31).getCell(3);
        XSSFCell c31_6 = sheet.getRow(31).getCell(6);
        XSSFCell c31_10 = sheet.getRow(31).getCell(10);
        c31_3.setCellValue(info.getXhgg());
        c31_6.setCellValue(info.getCcbh());
        c31_10.setCellValue(info.getSbjlzs());
        XSSFCell c32_3 = sheet.getRow(32).getCell(3);
        XSSFCell c32_6 = sheet.getRow(32).getCell(6);
        XSSFCell c32_10 = sheet.getRow(32).getCell(10);
        c32_3.setCellValue(info.getXhgg2());
        c32_6.setCellValue(info.getCcbh2());
        c32_10.setCellValue(info.getSbjlzs2());
        XSSFCell c37_3 = sheet.getRow(37).getCell(3);
        XSSFCell c37_11 = sheet.getRow(37).getCell(11);
        c37_3.setCellValue(info.getJcbgbh());
        c37_11.setCellValue(info.getJxjcrq());
        XSSFCell c39_12 = sheet.getRow(39).getCell(12);
        c39_12.setCellValue(info.getJyff());
        XSSFCell c40_3 = sheet.getRow(40).getCell(3);
        XSSFCell c40_8 = sheet.getRow(40).getCell(8);
        XSSFCell c40_12 = sheet.getRow(40).getCell(12);
        c40_3.setCellValue(info.getJckssj());
        c40_8.setCellValue(info.getJcjssj());
        c40_12.setCellValue(info.getJcdd());
        XSSFCell c42_3 = sheet.getRow(42).getCell(3);
        XSSFCell c42_5 = sheet.getRow(42).getCell(5);
        XSSFCell c42_8 = sheet.getRow(42).getCell(8);
        XSSFCell c42_10 = sheet.getRow(42).getCell(10);
        XSSFCell c42_13 = sheet.getRow(42).getCell(13);
        c42_3.setCellValue(info.getJcjg1());
        c42_5.setCellValue(info.getJcjg2());
        c42_8.setCellValue(info.getJcjg3());
        c42_10.setCellValue(info.getFdjzs());
        c42_13.setCellValue(Integer.valueOf(info.getMsyy()) == 0 ? "不可见" : "可见");
        XSSFCell c44_3 = sheet.getRow(44).getCell(3);
        c44_3.setCellValue(info.getJcjg());
        XSSFCell c45_3 = sheet.getRow(45).getCell(3);
        c45_3.setCellValue(info.getPfxz());
        XSSFCell c46_3 = sheet.getRow(46).getCell(3);
        c46_3.setCellValue(info.getJgpd());
        //插入图片
        insertPicCost(wb, sheet, info.getJxztzp(), 0, 49, 8, 58);
        insertPicCost(wb, sheet, info.getClmpzp(), 9, 49, 17, 58);
        insertPicCost(wb, sheet, info.getFdjmpzp(), 0, 59, 8, 69);
        insertPicCost(wb, sheet, info.getHclzzzp(), 9, 59, 17, 69);
        insertPicCost(wb, sheet, info.getJczp(), 0, 70, 8, 77);
        insertPicCost(wb, sheet, info.getJgzp(), 9, 70, 17, 77);
        //浏览器响应下载
        response.setContentType("application/vnd.ms-excel");
        try {
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(info.getJcbgbh() + ".xlsx", "utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        OutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int resetReportStatus(Integer reportId, int status) {
        ReportAudit audit = reportAuditMapper.selectByReportId(reportId);
        int count1=  reportMapper.updateStatusByKey(reportId,status);
        ReportAudit temp = new ReportAudit();
        temp.setAuditId(audit.getAuditId());
        temp.setStatus(status);
        temp.setUpdateTime(new Date());
        temp.setReportId(reportId);
       int count2 = reportAuditMapper.updateByPrimaryKey(temp);
        return count1  + count2;
    }

    @Override
    public Report getReportByUUid(String uuid) {
        return reportMapper.selectByUUid(uuid);
    }

    private void insertPicCost(XSSFWorkbook workBook, XSSFSheet topPic, String pic
            , int x1, int x2, int y1, int y2) {
        if (StringUtils.isEmpty(pic)) {
            return;
        } else {
            pic = FileConstants.REPORT_IMG_LOCAL_URL + pic.substring(pic.lastIndexOf("/") + 1);
        }
        BufferedImage bufferImg = null;//图片
        try {
            // 先把读进来的图片放到一个ByteArrayOutputStream中，以便产生ByteArray
            ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
            //将图片读到BufferedImage
            bufferImg = ImageIO.read(new File(pic));
            // 将图片写入流中
            ImageIO.write(bufferImg, "png", byteArrayOut);
            // 利用HSSFPatriarch将图片写入EXCEL
            Drawing patriarch = topPic.createDrawingPatriarch();
            //图片一导出到单元格B2中
            XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0,
                    (short) x1, x2, (short) y1, y2);
            // 插入图片
            patriarch.createPicture(anchor, workBook.addPicture(byteArrayOut
                    .toByteArray(), XSSFWorkbook.PICTURE_TYPE_PNG));
        } catch (IOException io) {
            log.error("插入失败 : " + pic);
        }
    }
}
